<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class HT_Model_administrator_models_voucheruser extends Zend_Db_Table {//ten class fai viet hoa

   protected $_db;

    public function __construct() {
        $this->_name = "voucher_user";
        $this->_db = Zend_Registry::get('dbMain');
        parent::init();
    }
    public function getAll($where){
        $sql = "select * from voucher_user where ".$where;                        
        $retval = $this->_db->fetchAll($sql);        
        return $retval;
    }
    public function findById($id){
        $sql = "select * from voucher_user where id = $id";
        $retval = $this->_db->fetchRow($sql);
        return $retval;
    }
    public function countByUserId($user_id,$partner_id){
        $sql = "select count(*) as count from voucher_user where user_id = $user_id AND partner_id = $partner_id";
        $retval = $this->_db->fetchRow($sql);
        return $retval['count'];
    }
    public function getAllVoucher(){
        $sql = "SELECT voucher_user.*,vouchers.voucher_name,vouchers.voucher_code,user.user_name,user.email FROM voucher_user LEFT JOIN vouchers ON voucher_user.voucher_id = vouchers.id INNER JOIN `user` ON voucher_user.user_id = user.wishid ORDER BY create_time DESC";
        $retval = $this->_db->fetchAll($sql);        
        return $retval;
    }
    public function getAllVoucherByPartner($partner_id){
        $sql = "SELECT voucher_user.*,vouchers.voucher_name,vouchers.voucher_code,user.user_name,user.email,user.firstname,user.lastname FROM voucher_user INNER JOIN vouchers ON voucher_user.voucher_id = vouchers.id INNER JOIN `user` ON voucher_user.user_id = user.wishid WHERE voucher_user.partner_id = $partner_id ORDER BY create_time DESC";        
        $retval = $this->_db->fetchAll($sql);        
        return $retval;
    }
}

?>
